<?php
/**
 * Created by JetBrains PhpStorm.
 * User: T420
 * Date: 11/29/12
 * Time: 10:42 PM
 * To change this template use File | Settings | File Templates.
 */
class Controllers_Manufacture extends Libs_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->model=new Models_Manufacture();
    }
    public function index()
    {
        $this->view->listmf=$this->model->getmanufacture();
        $this->view->render('manufacture/index');
    }
    public function del($param=null)
    {
        $this->model->delmf($param[0]);
        $this->index();
    }
    public function add()
    {
        $this->view->render('manufacture/add');
        if($_REQUEST['themhang'])
        {
            $tenhang=$_REQUEST['tenhang'];
            $trangthaihang=$_REQUEST['trangthaihang'];
            $check=$this->model->checkmf($tenhang);
            if(count($check))
                echo"<script>alert('Tên hãng này đã tồn tại, mời chọn 1 tên khác!'); onload=function(){frmthemhang.tenhang.focus();};</script>";
            else
            {
                $this->model->insertmf($tenhang,$trangthaihang);
                    echo"<script>alert('Thêm hãng thành công!'); location='/mymvc/administrator/manufacture';</script>";
            }
        }
    }
    public function update()
    {
        foreach($_POST['status'] as $key=>$value)
        {
            $this->model->updatehang($key,$value);
        }
        $this->index();
    }
}
